<?php
	function srch($srchby,$keywords)
	{
		if (!isset($keywords)){
			echo "<script language=javascript>history.go(-1);</script>";
			exit;
		}elseif ($keywords==''){
			echo "<script language=javascript>alert('Please input search words.');history.go(-1);</script>";
			exit;
		}
		
		$keywords=trim($keywords);
		include ("../../includes/conn.php");
		
		switch ($srchby){
			case '1' :
				$srch="select * from category where cname='Genes'";
				$srchres=mysql_query($srch,$db);
				$srchrw=mysql_num_rows($srchres);
				if ($srchrw>0){
					$sr=mysql_fetch_array($srchres);
					$csn=$sr['sn'];
					switch ($keywords){
						case "a":
						case "α":
						case "alpha":
						case "&#945;":
							$keywords="(sname like 'alpha%' or sname like '&#945;%')";
							break;
							
						case "b":
						case "β":
						case "beta":
						case "&#946;":
							$keywords="(sname like 'beta%' or sname like '&#946;%')";
							break;
							
						case "r":
						case "γ":
						case "gamma":
						case "&#947;":
							$keywords="(sname like 'gamma%' or sname like '&#947;%')";
							break;
							
						case "k":
						case "κ":
						case "kappa":
						case "&#954;":
							$keywords="(sname like 'kappa%' or sname like '&#954;%')";
							break;
							
						case "lambda":
						case "λ":
						case "&#955;":
							$keywords="(sname like 'lambda%' or sname like '&#955;%')";
							break;
							
						default:
							$keywords="sname like '$keywords%'";
					}
					$subs="select * from subcat where csn='$csn' and $keywords";
					$subres=mysql_query($subs,$db);
					$subrw=mysql_num_rows($subres);
					if ($subrw>0){
						$i=1; $j=1;
						echo "
						  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
							<tr>
							  <td height='29' colspan='3'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Gene's Name)</span> </td>
							</tr>
							<tr>
						";
						while ($subr=mysql_fetch_array($subres)){
							$ssn=$subr['sn'];
							$cd="select * from chdcat where csn='$csn' and ssn='$ssn' group by dname";
							$cdres=mysql_query($cd,$db);
							$cdrw=mysql_num_rows($cdres);
							if ($cdrw>0){
								$cdr=mysql_fetch_array($cdres);
								switch ($cdr['dname']){
									case "Antibodies":
										$lnk="../../ProdList.php";
										$cn="8";
										break;
									case "Adenovirus":
										$lnk="../../AdenoProdList.php";
										$cn="11";
										break;
									case "Lentivirus":
										$lnk="../../LentiProdList.php";
										$cn="10";
										break;
									case "siRNA":
										$lnk="../../siRNAProdList.php";
										$cn="9";
										break;
								}
							}
							if ($i<=3){
								echo "<td>&#8226;&nbsp;&nbsp;<a href=$lnk?cn=$cn&csn=$csn&ssn=$ssn&dsn=".$cdr['sn']."&srchby=$srchby class=designer>".$subr['sname']."</a></td>";
							}elseif ($j<=$subrw){
								$i=1;
								echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=$lnk?cn=$cn&csn=$csn&ssn=$ssn&dsn=".$cdr['sn']."&srchby=$srchby  class=designer>".$subr['sname']."</a></td>";
							}
							$i++; $j++;
						}
						for ($m=1;$m<=(3-$i);$m++){
							echo "<td>&nbsp;</td>";
						}
						echo "</tr></table>";
					}else{
						echo "<script language=javascript>alert('Sorry, no such Gene Name.');location.href='../../index.php?cn=0&srchby=$srchby';</script>";
						exit;
					}
				}
				break;
			case '2': //search by CatNO.
				
				//search antibodies
				$prd="select * from products where catNo like '$keywords%'";
				$prdres=mysql_query($prd,$db);
				$prw=mysql_num_rows($prdres);
				if ($prw>0){
					$i=1; $j=1;
					echo "
					  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
						<tr>
						  <td height='29' colspan='5'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Catalogue Number)</span> </td>
						</tr>
						<tr>
					";
					while ($pr=mysql_fetch_array($prdres)){
						$csn=$pr['csn'];
						$ssn=$pr['ssn'];
						$dsn=$pr['dsn'];
						$catno=$pr['catNo'];
						if ($i<=5){
							echo "<td>&#8226;&nbsp;&nbsp;<a href=../../ProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
						}elseif ($j<=$prw){
							$i=1;
							echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=../../ProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
						}
						$i++; $j++;
					}
					for ($m=1;$m<=(5-$i);$m++){
						echo "<td>&nbsp;</td>";
					}
					echo "</tr></table>";
					break;
				}
					
				//search siRNA
					$prd="select * from prodsirna where catNo like '$keywords%'";
					$prdres=mysql_query($prd,$db);
					$prw=mysql_num_rows($prdres);
					if ($prw>0){
						$i=1; $j=1;
						echo "
						  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
							<tr>
							  <td height='29' colspan='5'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Catalogue Number)</span> </td>
							</tr>
							<tr>
						";
						while ($pr=mysql_fetch_array($prdres)){
							$csn=$pr['csn'];
							$ssn=$pr['ssn'];
							$dsn=$pr['dsn'];
							$catno=$pr['catNo'];
							if ($i<=5){
								echo "<td>&#8226;&nbsp;&nbsp;<a href=../../siRNAProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}elseif ($j<=$prw){
								$i=1;
								echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=../../siRNAProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}
							$i++; $j++;
						}
						for ($m=1;$m<=(5-$i);$m++){
							echo "<td>&nbsp;</td>";
						}
						echo "</tr></table>";
						break;
					}
				
				//search Lentivirus
					$prd="select * from prodlenti where catNo like '$keywords%'";
					$prdres=mysql_query($prd,$db);
					$prw=mysql_num_rows($prdres);
					if ($prw>0){
						$i=1; $j=1;
						echo "
						  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
							<tr>
							  <td height='29' colspan='5'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Catalogue Number)</span> </td>
							</tr>
							<tr>
						";
						while ($pr=mysql_fetch_array($prdres)){
							$csn=$pr['csn'];
							$ssn=$pr['ssn'];
							$dsn=$pr['dsn'];
							$catno=$pr['catNo'];
							if ($i<=5){
								echo "<td>&#8226;&nbsp;&nbsp;<a href=../../LentiProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}elseif ($j<=$prw){
								$i=1;
								echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=../../LentiProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}
							$i++; $j++;
						}
						for ($m=1;$m<=(5-$i);$m++){
							echo "<td>&nbsp;</td>";
						}
						echo "</tr></table>";
						break;
					}
					
				
				//search Adenovirus
					$prd="select * from prodadenovirus where catNo like '$keywords%'";
					$prdres=mysql_query($prd,$db);
					$prw=mysql_num_rows($prdres);
					if ($prw>0){
						$i=1; $j=1;
						echo "
						  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
							<tr>
							  <td height='29' colspan='5'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Catalogue Number)</span> </td>
							</tr>
							<tr>
						";
						while ($pr=mysql_fetch_array($prdres)){
							$csn=$pr['csn'];
							$ssn=$pr['ssn'];
							$dsn=$pr['dsn'];
							$catno=$pr['catNo'];
							if ($i<=5){
								echo "<td>&#8226;&nbsp;&nbsp;<a href=../../AdenoProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}elseif ($j<=$prw){
								$i=1;
								echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=../../AdenoProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}
							$i++; $j++;
						}
						for ($m=1;$m<=(5-$i);$m++){
							echo "<td>&nbsp;</td>";
						}
						echo "</tr></table>";
						break;
					}
					
					
				//search other exceptions
					$prd="select * from prodothers where catNo like '$keywords%'";
					$prdres=mysql_query($prd,$db);
					$prw=mysql_num_rows($prdres);
					if ($prw>0){
						$i=1; $j=1;
						echo "
						  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
							<tr>
							  <td height='29' colspan='5'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Catalogue Number)</span> </td>
							</tr>
							<tr>
						";
						while ($pr=mysql_fetch_array($prdres)){
							$catno=$pr['catNo'];
							$csn=14;
							if ($i<=5){
								echo "<td>&#8226;&nbsp;&nbsp;<a href=../../otherProds.php?cn=0&pcat=$csn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}elseif ($j<=$prw){
								$i=1;
								echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=../../otherProds?cn=0&pcat=$csn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}
							$i++; $j++;
						}
						for ($m=1;$m<=(5-$i);$m++){
							echo "<td>&nbsp;</td>";
						}
						echo "</tr></table>";
						break;
					}
					
	
				//search PCR
					$prd="select * from prodpcr where catNo like '$keywords%'";
					$prdres=mysql_query($prd,$db);
					$prw=mysql_num_rows($prdres);
					if ($prw>0){
						$i=1; $j=1;
						echo "
						  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
							<tr>
							  <td height='29' colspan='5'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Catalogue Number)</span> </td>
							</tr>
							<tr>
						";
						while ($pr=mysql_fetch_array($prdres)){
							$csn=$pr['csn'];
							$ssn=$pr['ssn'];
							$dsn=$pr['dsn'];
							$catno=$pr['catNo'];
							if ($i<=5){
								echo "<td>&#8226;&nbsp;&nbsp;<a href=../../moreproduct/ProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}elseif ($j<=$prw){
								$i=1;
								echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=../../moreproduct/ProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}
							$i++; $j++;
						}
						for ($m=1;$m<=(5-$i);$m++){
							echo "<td>&nbsp;</td>";
						}
						echo "</tr></table>";
						break;
					}
					
				//search RNA
					$prd="select * from prodrna where catNo like '$keywords%'";
					$prdres=mysql_query($prd,$db);
					$prw=mysql_num_rows($prdres);
					if ($prw>0){
						$i=1; $j=1;
						echo "
						  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
							<tr>
							  <td height='29' colspan='5'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Catalogue Number)</span> </td>
							</tr>
							<tr>
						";
						while ($pr=mysql_fetch_array($prdres)){
							$csn=$pr['csn'];
							$ssn=$pr['ssn'];
							$dsn=$pr['dsn'];
							$catno=$pr['catNo'];
							if ($i<=5){
								echo "<td>&#8226;&nbsp;&nbsp;<a href=../../dispOnesiRNA.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}elseif ($j<=$prw){
								$i=1;
								echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=../../dispOnesiRNA.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}
							$i++; $j++;
						}
						for ($m=1;$m<=(5-$i);$m++){
							echo "<td>&nbsp;</td>";
						}
						echo "</tr></table>";
						break;
					}
					
				//search Second Antibodies
					$prd="select * from prodsecondanti where catNo like '$keywords%'";
					$prdres=mysql_query($prd,$db);
					$prw=mysql_num_rows($prdres);
					if ($prw>0){
						$i=1; $j=1;
						echo "
						  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
							<tr>
							  <td height='29' colspan='5'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Catalogue Number)</span> </td>
							</tr>
							<tr>
						";
						while ($pr=mysql_fetch_array($prdres)){
							$csn=$pr['csn'];
							$ssn=$pr['ssn'];
							$dsn=$pr['dsn'];
							$catno=$pr['catNo'];
							if ($i<=5){
								echo "<td>&#8226;&nbsp;&nbsp;<a href=../../moreproduct/ProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}elseif ($j<=$prw){
								$i=1;
								echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=../../moreproduct/ProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}
							$i++; $j++;
						}
						for ($m=1;$m<=(5-$i);$m++){
							echo "<td>&nbsp;</td>";
						}
						echo "</tr></table>";
						break;
					}
					
				//search Transfections
					$prd="select * from prodtrans where catNo like '$keywords%'";
					$prdres=mysql_query($prd,$db);
					$prw=mysql_num_rows($prdres);
					if ($prw>0){
						$i=1; $j=1;
						echo "
						  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
							<tr>
							  <td height='29' colspan='5'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Catalogue Number)</span> </td>
							</tr>
							<tr>
						";
						while ($pr=mysql_fetch_array($prdres)){
							$csn=$pr['csn'];
							$ssn=$pr['ssn'];
							$dsn=$pr['dsn'];
							$catno=$pr['catNo'];
							if ($i<=5){
								echo "<td>&#8226;&nbsp;&nbsp;<a href=../../moreproduct/ProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}elseif ($j<=$prw){
								$i=1;
								echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=../../moreproduct/ProdList.php?cn=$csn&ssn=$ssn&dsn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}
							$i++; $j++;
						}
						for ($m=1;$m<=(5-$i);$m++){
							echo "<td>&nbsp;</td>";
						}
						echo "</tr></table>";
						break;
					}
					
				//search old database for Tag Antibody products
					include ("../../includes/connabm.php");
					$prd="select * from products where catNo like '$keywords%'";
					$prdres=mysql_query($prd,$db);
					$prw=mysql_num_rows($prdres);
					if ($prw>0){
						$i=1; $j=1;
						echo "
						  <table width='100%' border='0' cellpadding='0' cellspacing='0' class='cont-b'>
							<tr>
							  <td height='29' colspan='5'><span class='cont-y'>Search Result:</span> <span class='smal'>(By Catalogue Number)</span> </td>
							</tr>
							<tr>
						";
						while ($pr=mysql_fetch_array($prdres)){
							$csn=$pr['gno'];
							$ssn=$pr['subno'];
							$dsn=$pr['chdno'];
							$catno=$pr['catNo'];
							if ($i<=5){
								echo "<td>&#8226;&nbsp;&nbsp;<a href=../../TagAntibody/dispOne.php?cn=8&csn=$ssn&ssn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}elseif ($j<=$prw){
								$i=1;
								echo "</tr><tr height=20><td>&#8226;&nbsp;&nbsp;<a href=../../TagAntibody/dispOne.php?cn=8&csn=$ssn&ssn=$dsn&catno=$catno&srchby=$srchby  class=designer>$catno</a></td>";
							}
							$i++; $j++;
						}
						for ($m=1;$m<=(5-$i);$m++){
							echo "<td>&nbsp;</td>";
						}
						echo "</tr></table>";
						break;
					}else{
						echo "<script language=javascript>alert('Sorry, no such product.');location.href='../../index.php';</script>";
						exit;
					}
		}
	}
?>